using Godot;
using System;
using BrdgeBuider.Scripts.enums;

public partial class AnimationComponent : AnimatedSprite2D
{
	private PlatformCharacter character;
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		character = GetParent<PlatformCharacter>();
	}

	private float _preX=0;
	private bool _preFlip = false;
	private void _UpdateAnimation()
	{
		if ((_preX * character.Velocity.X < 0||_preX==0)&&character.Velocity.X<0)
		{
			FlipH = true;
		}
		else if ((_preX * character.Velocity.X < 0||_preX==0)&&character.Velocity.X>0)
		{
			FlipH = false;
		}
		if (_preFlip!=FlipH)
		{
			Position =new Vector2(Position.X* -1,Position.Y);
		}
		_preFlip = FlipH;
		_preX = character.Velocity.X;
		
		if (character.Velocity.X!=0)
		{
			Play("walk");
		}
		else
		{
			Play("idle");
		}

		if (character.JumpStatus!=JumpStatus.Land)
		{
			Pause();
		}
		else
		{
			Play();
		}
	}
	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		_UpdateAnimation();
	}
}
